<template>
	<div class="aid">
		<div class="base">
			<p class="fixed-top">
				{{ importText.name }}
				<a-icon @click="closeFunction" type="close" />
			</p>
			<div class="main">
				<a-form :form="form">
					<p v-if="importText.name=='学生履历导入'" style="font-size: 14px;color: red;text-align: left;padding-left: 80px;">请选择学期后再导入学生履历</p>
					<a-form-model-item label="学期" v-if="importText.name=='学生履历导入'">
						<a-select :allowClear="true" @change="xueqiFun" v-model="semesterID" placeholder="全部"
							optionFilterProp="children" showSearch>
							<a-select-option v-for="(item, index) in SemesterList" :key="index" :value="item.ID">
								{{ item.Name }}
							</a-select-option>
						</a-select>
					</a-form-model-item>
					<a-form-model-item label="文件上传">
						<a-upload name="file" :disabled="seStatus" v-if="importText.name=='学生履历导入'" :action="requestUrl + importText.url" accept=".xlsx,application/vnd.ms-excel" 
						:headers="{ ticket: token }" :data="{semesterID:semesterID}"  @change="uploadChange" :fileList="fileList">
							<a-button v-if="fileList.length==0">
								<a-icon type="upload" />
								文件选择
							</a-button>
						</a-upload>
						<a-upload v-else name="file" :action="requestUrl + importText.url" accept=".xlsx,application/vnd.ms-excel"
						:headers="{ ticket: token }" @change="uploadChange" :fileList="fileList">
							<a-button v-if="fileList.length==0">
								<a-icon type="upload" />
								文件选择
							</a-button>
						</a-upload>
					</a-form-model-item>
					<a-form-model-item label="模板下载">
						<div style="color:blue;cursor: pointer;" @click="download()">下载</div>
					</a-form-model-item>
					<a-form-item class="fixed-bottom">
						<!-- <a-button type="primary" @click="handleSubmit" :loading="loading">完成</a-button> -->
						<a-button style="margin-left: 10px;" @click="closeFunction">关闭</a-button>
					</a-form-item>
				</a-form>
			</div>
		</div>
	</div>
</template>

<script>
import {
	DoGetActivityMemberTypeListCommon,
	UserActivityMemberDoImportFormText,
	ManageActivityMemberDoImportFormText,
	DoAddActivityMember,
	GetActivityTypePrizeListCommon,
	UserDoAddActivityMemberPrize,
	AddActivityMemberPrize,
	DoGetSemesterListCommon
} from '@/api/follow';
import Cache from '@/utils/cache';
export default {
	props: {
		importText: Object
	},
	watch: {
		importText: function(importText) {
			if (importText.name == '成员导入-管理员' || importText.name == '成员导入-用户') {
				this.getOtherList();
			}
			if (importText.name == '奖项导入-管理员' || importText.name == '奖项导入-用户') {
				this.getPrizeList();
			}
			if(importText.name=='学生履历导入'){
				this.getOtherList2()
			}
		}
	},
	data() {
		return {
			seStatus:true,
			semesterID:'',
			importIf: false,
			importData: [],
			fileList: [],
			loading: false,
			formLayout: 'horizontal',
			form: this.$form.createForm(this, {
				name: 'coordinated'
			}),
			// form:{
			// 	semesterID:''
			// },
			ActivityMemberTypeList: [],
			ActivityTypePrizeList: [],
			requestUrl: this.global.requestUrl,
			loadUrl: this.global.loadUrl,
			token: Cache.get('token'),
			SemesterList:[]
		};
	},
	async created() {
		this.semesterID=''
	},
	methods: {
		xueqiFun(e){
			console.log(e);
			if(e!=undefined){
				this.seStatus=false
			}else{
				this.seStatus=true
			}
		},
		beforeUpload(e){
			console.log('上传前')
			if(this.semesterID==''){
				return false;
			}
		},
		async getOtherList2(){
			let res3 = await DoGetSemesterListCommon();
			this.SemesterList = res3.data.data;
		},
		download(){
			window.open(this.loadUrl+this.importText.href,'_blank')
		},
		async getPrizeList() {
			let res = await GetActivityTypePrizeListCommon({ activityTypeID: this.$route.query.TypeID });
			this.ActivityTypePrizeList = res.data.data;
		},
		async getOtherList() {
			let res = await DoGetActivityMemberTypeListCommon();
			this.ActivityMemberTypeList = res.data.data;
		},
		fileload() {
			window.open(this.loadUrl + this.importText.href, '_blank');
		},
		uploadChange(info) {
			let { fileList } = info;
			const status = info.file.status;
			if (status === 'done') {
				if (info.file.response.code == 0) {
					this.$message.success(info.file.response.msg);
					this.fileList = [...fileList]; //重点
					// setTimeout((res)=>{
					// 	this.fileList = []
					// },500)
				} else {
					this.$message.error(info.file.response.msg);
					this.fileList = this.fileList.splice(this.fileList.length - 1, 1);
				}
			}
			this.fileList = [...fileList]; //重点
		},
		// uploadChange(info) {
		// 	console.log(info)
		// 	if (info.file.status !== 'uploading') {
		// 	        console.log(info.file, info.fileList);
		// 	      }
		// 	      if (info.file.status === 'done') {
		// 	        this.$message.success(`${info.file.name} file uploaded successfully`);
		// 	      } else if (info.file.status === 'error') {
		// 	        this.$message.error(`${info.file.name} file upload failed.`);
		// 	      }
		// },
		closeFunction(data) {
			this.importIf = false;
			this.fileList = []
			this.form.resetFields();
			this.$emit('closeFun', 1);
		},
		handleRemove(file) {
			const index = this.fileList.indexOf(file);
			const newFileList = this.fileList.slice();
			newFileList.splice(index, 1);
			this.fileList = newFileList;
		},
		beforeUpload(file) {
			console.log(file);
			this.fileList = [...this.fileList, file];
			return false;
		},
		handleSubmit(e) {
			this.form.validateFields(async (err, values) => {
				if (!err) {
					let that = this;
					let data = {};
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
.aid .base {
	width: 1000px;
	margin-left: -500px;
}
/deep/.ant-form {
	margin-top: 50px;
	padding-bottom: 50px;
}
/deep/.ant-form-item {
	margin: 20px 50px;
	display: flex;
}
/deep/.ant-form-item-label {
	width: 100px;
	overflow: hidden;
	white-space: nowrap;
	text-overflow: ellipsis;
	text-align: right;
}
/deep/.ant-form-item-control-wrapper {
	flex: 1;
}
/deep/.ant-calendar-picker {
	width: 100% !important;
}
</style>
